import 'package:flutter/material.dart';

void main() {
  // 1.运行应用程序
  runApp(const MaterialApp(home: Main()));
}

class Main extends StatelessWidget {
  const Main({super.key});
 
  @override
  Widget build(BuildContext context) {
    // 2.构建应用程序界面
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'CustomScrollView组件 - 自定义滚动容器',
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.black,
      ),
      // 中间内容
      body: Container(
        padding: const EdgeInsets.all(10),
        color: Colors.black12,
        child:  CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: Container(
                height: 50,
                color: Colors.red,),
              ),
          const SliverPadding(padding: EdgeInsets.only(bottom: 10)),
            SliverGrid.builder(
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3,
                mainAxisSpacing: 10,
                crossAxisSpacing: 10,
                childAspectRatio: 10 / 6,
              ),
                itemCount: 6,
 // 函数如果只返回组件，可使用箭头函数化简
              itemBuilder: (context, index) => Container(
                color: Colors.pink,
                alignment: Alignment.center,
                child: Text('黑马程序员$index'),
              ),
            ),
           const SliverPadding(padding: EdgeInsets.only(bottom: 10)),
            SliverList.separated(
              itemBuilder: (context, index) {
                // 函数内部业务逻辑，最后返回组件
                return Container(
                  color: Colors.amber,
                  height: 100,
                  alignment: Alignment.center,
                  child: Text('黑马程序员$index'),
                );
              },
              separatorBuilder: (BuildContext context,int index) {
                return Container(
                  height: 10,
                  color: Colors.transparent,
                );
              },
              itemCount: 20,
            ),
             ],
         ),
      ),
    );
  }
}